/*
	create By Jane 
	时间格式化 yyyy-MM-dd hh:mm:ss
 **/
Date.prototype.Format = function(fmt = 'yyyy-MM-dd hh:mm:ss') {
  const o = {
    'M+': this.getMonth() + 1, //月份
    'd+': this.getDate(), //日
    'h+': this.getHours(), //小时
    'm+': this.getMinutes(), //分
    's+': this.getSeconds(), //秒
    'q+': Math.floor((this.getMonth() + 3) / 3), //季度
    S: this.getMilliseconds(), //毫秒
  };
  if (/(y+)/.test(fmt)) {
    fmt = fmt.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  for (const k in o) {
    if (new RegExp('(' + k + ')').test(fmt)) {
      fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
    }
  }
  return fmt;
};
Date.prototype.FormatDateTime = function() {
  return this.Format('yyyy-MM-dd hh:mm:ss');
};
Date.prototype.FormatDate = function() {
  return this.Format('yyyy-MM-dd');
};
Date.prototype.FormatTime = function() {
  return this.Format('hh:mm:ss');
};

//时间简化 转换为 刚刚 今天 昨天 之类
Date.prototype.Short = function() {
  const dateTimeStamp = this.getTime();
  const minute = 1000 * 60;      //把分，时，天，周，半个月，一个月用毫秒表示
  const hour = minute * 60;
  const day = hour * 24;
  const week = day * 7;
  const month = day * 30;
  const now = new Date().getTime();   //获取当前时间毫秒
  const diffValue = now - dateTimeStamp;//时间差

  if (diffValue < 0) {
    return;
  }
  const minC = diffValue / minute;  //计算时间差的分，时，天，周，月
  const hourC = diffValue / hour;
  const dayC = diffValue / day;
  const weekC = diffValue / week;
  const monthC = diffValue / month;
  let result;
  if (monthC >= 1 && monthC <= 3) {
    result = ' ' + monthC + '月前';
  } else if (weekC >= 1 && weekC <= 3) {
    result = ' ' + weekC + '周前';
  } else if (dayC >= 1 && dayC <= 6) {
    result = ' ' + dayC + '天前';
  } else if (hourC >= 1 && hourC <= 23) {
    result = ' ' + hourC + '小时前';
  } else if (minC >= 1 && minC <= 59) {
    result = ' ' + minC + '分钟前';
  } else if (diffValue >= 0 && diffValue <= minute) {
    result = '刚刚';
  } else {
    const datetime = new Date();
    datetime.setTime(dateTimeStamp);
    const Nyear = datetime.getFullYear();
    const Nmonth = datetime.getMonth() + 1 < 10 ? '0' + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
    const Ndate = datetime.getDate() < 10 ? '0' + datetime.getDate() : datetime.getDate();
    // var Nhour = datetime.getHours() < 10 ? "0" + datetime.getHours() : datetime.getHours();
    // var Nminute = datetime.getMinutes() < 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
    // var Nsecond = datetime.getSeconds() < 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
    result = Nyear + '-' + Nmonth + '-' + Ndate;
  }
  return result;
};
